package com.shujia.scala

import java.io.{FileNotFoundException, FileReader}

object Demo4Exception {
  def main(args: Array[String]): Unit = {
    /**
     * 异常捕获
     */


    try {
      val reader = new FileReader("data/students.txt")

      //手动抛出异常
      throw new RuntimeException("手动抛出异常")
    } catch {
      //捕获异常，通过异常类型进行匹配
      case e: FileNotFoundException =>
        println("找不到文件异常")

      case e: RuntimeException =>
        println("运行时异常")
        e.printStackTrace()

    } finally {
      println("都会执行")
    }


    println("测试")
  }

}
